<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<HEAD>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<TITLE>帐户类型管理</TITLE>
	<script language="javascript" src="../script/common.js"></script>
	<script language="javascript">
		//全局变量
		var qt = {};				//数据表格对象

		//页面加载方法
		function load(){
			Eui.showNavigation();
			setPages(["listview","detview","update"]);
			Common.initDict(searchForm.baseAccountType,"base_account_type","全 部");
			createTable();		
		}
		/**查询部分**/

		//生成表格，创建QueryTable对象
		function createTable(){
			var columns = []	
				columns[0] = {defOrder:"ASC"};			
			columns[3] = {title:"操作",width:"18%",render:operator,align:"center",order:false} 	
			qt = new QueryTable("card_code_query","searchForm","datalist",columns,{
				buttons:[
					{value:"增加",actions:addCode}
				]
			});
			
		}
		function addCode(){
			cardCodeForm.reset();
			switchPage("detview")
		}
		function onSave(){
			if(!checkForm(cardCodeForm))return;
				if(showQuestion("您确认要创建此编码吗?")==true){
					var orgId = cardCodeForm.orgId.value;
					var cardCode = cardCodeForm.cardCode.value;
					var name = cardCodeForm.name.value;
					DWR.call('orgCardCodeService.addOrgCardCode',orgId,cardCode,name,function(v){
						showInformation("增加成功!");
						switchPage("listview");
						qt.showTable();
					},{disCtrl:$('saveBut')});
				}
		}
	//选择机构方法
		function searchSelOrg(form){
			SystemMgnt.selOrg(function(sorg) {
				form.orgId.value = sorg.id;
          		form.orgName.value = sorg.name;
			},{funcType : Constants.SELORG_ALL});
		}
	function operator(v,r){
		return "<div><a href=# onclick=\"onEdit("+r[3]+");return false;\">修改</a> <a href=# onclick=\"onDelete("+r[3]+");return false;\">删除</a></div>";
	}
	function onEdit(id){
	    if (id != null){
			DWR.call("orgCardCodeService.getCardCode",id,function(orgCardCode){
				orgCardCode.code = orgCardCode.code+""
				while(orgCardCode.code.length< 4){
					orgCardCode.code = "0"+orgCardCode.code
				}
				orgCardCode.cardCode = orgCardCode.code;
				orgCardCode.orgName = orgCardCode.org.name;
				orgCardCode.orgId = orgCardCode.org.id;
				Common.setValues(updateCardCodeForm,orgCardCode);
				
				switchPage('update');
			});
		}
	}
	function update(){
		if(!checkForm(updateCardCodeForm))return;
		if(showQuestion("您确认要修改此编码吗?")==true){
			var orgId = updateCardCodeForm.orgId.value;
			var cardCode = updateCardCodeForm.cardCode.value;
			var name = updateCardCodeForm.name.value;
			var id = updateCardCodeForm.id.value;
			DWR.call('orgCardCodeService.updateOrgCardCode',orgId,cardCode,id,name,function(v){
				showInformation("修改成功!");
				switchPage("listview");
				qt.showTable();
			},{disCtrl:$('updateBut')});
		}
	}
	function onDelete(id){
		if(!(showQuestion("您确定删除吗?"))){
			return;
		}
		DWR.call("orgCardCodeService.deleteOrgCardCode",id,function(){
			showInformation("删除成功!");
			qt.showTable();
		},{blockScreen:"true"});
	}
	</script>
</HEAD>
<body onload="load()">
	<!--页面导航-->
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="listview" >	
		<!--查询条件form-->
		<form id="searchForm" name="searchForm">
			<input type="hidden" name="orgId" id="orgId">
			<div class="searchForm">
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 >
					<tr>
				    	<td><label>区域名称</label> <input type="text"  name="orgName"> <a class="orga" href="#" onclick="searchSelOrg(searchForm);">&nbsp;&nbsp;</a></td>
						<td><label>编&nbsp;&nbsp;&nbsp;&nbsp;码</label> <input type="text" name="code" onblur="checkV(this,'number')"></td>	
						<td><button type="button" onclick="qt.showTable()">查 询</button></td> 
					</tr> 
				</table>
			</div>
		</form>
		<!--查询结构列表-->
		<div id="datalist"></div>	
	</div>	
	
	<div id="detview" style="display:none;">
		<div class="form">
		<form id="cardCodeForm" name="cardCodeForm">
			<input type="hidden" name="orgId" id="orgId">
			<div class="formTitle">区域卡片编码管理</div>
			<table cellSpacing=0 cellPadding=4 width="100%" border=0 >
				<tr>
					<td><label>编&nbsp;&nbsp;&nbsp;&nbsp;码</label> <input type="text" name="cardCode" onblur="checkV(this,'number',true)" maxlength="4"> <span class="des">*</span></td>
					<td><label>区域名称</label> <input type="text" name="orgName" onblur="checkV(this,'',true)" readonly class="readonly"> <a class="orga" href="#" onclick="searchSelOrg(cardCodeForm);">&nbsp;&nbsp;</a> <span class="des">*</span></td>
					<td><label>说&nbsp;&nbsp;&nbsp;&nbsp;明</label> <input type="text" name="name" maxlength="8"></td>
				</tr>
			</table>
		</form>
		</div>
		<p><button type="submit" id="saveBut" name="saveBut" onclick="onSave()">确 定</button> <button type="submit" id="saveBut" name="saveBut" onclick="switchPage('listview')">取 消</button></p>
	</div>
	
	<div id="update" style="display:none;">
		<div class="form">
		<form id="updateCardCodeForm" name="updateCardCodeForm">
			<input type="hidden" name="orgId" id="orgId">
			<input type="hidden" name="id" id="id">
			<div class="formTitle">区域卡片编码管理</div>
			<table cellSpacing=0 cellPadding=4 width="100%" border=0 >
				<tr>
					<td><label>编&nbsp;&nbsp;&nbsp;&nbsp;码</label> <input type="text" name="cardCode" onblur="checkV(this,'number',true)" maxlength="4"> <span class="des">*</span></td>
					<td><label>区域名称</label> <input type="text" name="orgName" readonly class="readonly" onblur="checkV(this,'',true)"></td>
					<td><label>说&nbsp;&nbsp;&nbsp;&nbsp;明</label> <input type="text" name="name" maxlength="8"></td>
				</tr>
			</table>
		</form>
		</div>
		<p><button type="submit" id="updateBut" name="updateBut" onclick="update()">确 定</button> <button type="submit" id="saveBut" name="saveBut" onclick="switchPage('listview')">取 消</button></p>
	</div>
 </body>
</HTML>
